<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Provider;

use App\Service\JoinRoomService;
use Base\BaseData;
use Hyperf\Utils\ApplicationContext;

class DispatchMessage
{
    public function dispatch(BaseData $baseData, int $fd)
    {
        $container = ApplicationContext::getContainer();
        switch ($baseData->getBody()) {
            case 'join_room_request':
                return $container->get(JoinRoomService::class)->joinRoom($baseData->getJoinRoomRequest(), $fd);
            default:
                throw new \Exception('Invalid body', 400);
        }
    }
}
